package com.gupao.gupaoeduvippattern.javaBase.thread.day02;

/**
 * @author Administrator
 * @date 2020-12-08 10:59
 */
public class ThreadDemo1 {

    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        ticket.setSum(10);
        UserA userA = new UserA(ticket);
        UserB userB = new UserB(ticket);
        UserC userC = new UserC(ticket);

        new Thread(new UserA(ticket)).start();
        new Thread(new UserA(ticket)).start();
        new Thread(new UserA(ticket)).start();
        new Thread(new UserA(ticket)).start();
        new Thread(new UserA(ticket)).start();

        new Thread(new UserB(ticket)).start();
        new Thread(new UserB(ticket)).start();
        new Thread(new UserB(ticket)).start();
        new Thread(new UserB(ticket)).start();
        new Thread(new UserB(ticket)).start();

        new Thread(new UserC(ticket)).start();
        new Thread(new UserC(ticket)).start();
        new Thread(new UserC(ticket)).start();
        new Thread(new UserC(ticket)).start();
        new Thread(new UserC(ticket)).start();

//        new Thread(userB).start();
//        new Thread(userC).start();


    }

}

class UserA implements Runnable{

    private Ticket ticket;

    public UserA(Ticket ticket){
        this.ticket = ticket;
    }

    @Override
    public void run() {
        ticket.buyTicket();
    }
}

class UserB implements Runnable{

    private Ticket ticket;

    public UserB(Ticket ticket){
        this.ticket = ticket;
    }

    @Override
    public void run() {
        ticket.buyTicket();
    }
}

class UserC implements Runnable{

    private Ticket ticket;

    public UserC(Ticket ticket){
        this.ticket = ticket;
    }

    @Override
    public void run() {
        ticket.buyTicket();
    }
}

